/*
 * send ajax requests
 * @param type      [POST,GET]
 * @param url       url of requested page
 * @param data      the data which send to database
 * @param success   function which be callad after request successed
 *                  also content the response in first paramter
 * @error error     function called on failer    
 */
HQ = {}
HQ.ajax = function(type,url,data,success,error){
    if(!error)
    {
            error = function(){
                window.location.reload()
            }
    }
    $.ajax({
        type:type,
        url:url,
        data:data,
        success:success,
        error:error
    })
}

/*
 * block site page
 * @param title : title of waiting page
 */
HQ.blockPage = function (title){
    var theme = true
    if(navigator.appName == "Microsoft Internet Explorer")
    {
        theme=false
    }
    $.blockUI({
        theme:     theme, 
        message:  '<p><center>'+__('Please wait')+'.....<div class="wait">&nbsp;</div></center></p>',
        title: title,
        css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            color: '#fff' 
        }
    });
}

/*
 * unblock div untill ajax finished
 */
HQ.unBlockPage = function (){
    $.unblockUI();
}

/*
 * show confirm message
 * @param msg - the message which will be show to user
 * @return boolean  
 */
HQ.confirmDialog = function(msg,conftirmFunction)
{
    var value=''
    $('body').append('<div id="confirm_msg">'+msg+'</div>')
    $('#confirm_msg').dialog({
        width: 'auto',
        draggable: false,
        resizable: false,
        modal: true,
        buttons: {
            'ok': function() {
                conftirmFunction()
                $( this ).dialog( "close" );
            },
            "cancel": function() {
                $( this ).dialog( "close" );
            }
        }
    });
}
	
/*
 * Mina
 */
function validateNumber(str)
{
    var pattern= new RegExp(/^[0-9]+$/);
    return pattern.test(str);
}
var onlyNumbersAllow = function(event) {
    // Allow: backspace, delete, tab, escape, and enter
    if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || 
        // Allow: Ctrl+A
        (event.keyCode == 65 && event.ctrlKey === true) || 
        // Allow: home, end, left, right
        (event.keyCode >= 35 && event.keyCode <= 39)) {
        // let it happen, don't do anything
        return;
    }
    else 
    {
        // Ensure that it is a number and stop the keypress
        if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
            event.preventDefault(); 
        }  
    }
}